//
//  CLBook.swift
//  CJBookReader
//
//  Created by colin on 2019/3/22.
//  Copyright © 2019 lidi. All rights reserved.
//

import UIKit

class CLBook {
    var chapters = [CLBookChapter]()
    init(chapters:[JSONObject]?) {
        if let value = chapters, !value.isEmpty {
            self.loadChapter(chapters: value)
        }
    }
    
    private func loadChapter(chapters:[JSONObject]) {
        for index in 0 ..< chapters.count {
            let chapter = chapters[index]
            self.chapters.append(CLBookChapter(chapterJSON: chapter))
            if let children = chapter["children"] as? [JSONObject], !children.isEmpty {
                self.loadChapter(chapters: children)
            }
        }
    }
    
}
